package com.yoomiito.app.widget.dialog

import android.content.Context
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.widget.TextView
import com.yoomiito.app.R
import com.yoomiito.app.adapter.dialog.GoodsListDialogAdapter
import com.yoomiito.app.base.BaseActivity
import com.yoomiito.app.model.video.VideoOtherInfo
import com.yoomiito.app.utils.DataUtils
import com.yoomiito.app.utils.RouterUtils

class GoodsListDialog(val context: BaseActivity<*>,val productBean: List<VideoOtherInfo.ProductBean>?) :BaseDialog(context, R.style.dialog_2){
    private var mRecyclerView: androidx.recyclerview.widget.RecyclerView?=null
    private var title:TextView?=null
    private val mAdapter = GoodsListDialogAdapter()
    override fun setView(): View {
        val view = LayoutInflater.from(context).inflate(R.layout.dialog_goods_list,null,false)
        mRecyclerView = view.findViewById(R.id.rcy)
        title = view.findViewById(R.id.titleTv)
        title?.text = "共${productBean?.size}件商品"
        setmHeightPercent(0.67)
        setWidthPercent(1.toDouble())
        setmGravity(Gravity.BOTTOM)
        setCanceledOnTouchOutside(true)
        mRecyclerView?.layoutManager = androidx.recyclerview.widget.LinearLayoutManager(context)
        mRecyclerView?.adapter = mAdapter
        mAdapter.setOnItemClickListener { adapter, view, position ->
            val goods = mAdapter.data[position]
            //1淘宝商品2礼包商品3爆品商品4优品商品5区代商品
            RouterUtils.toGoodsDetail(context,goods.id,DataUtils.getGoodsType(goods.type))
        }
        mAdapter.setNewData(productBean)
        view.findViewById<View>(R.id.close).setOnClickListener { dismiss() }
        return view
    }
}